package special;

/**
 * @author kunkun
 * @className LeetCode_75
 * @Description 颜色分类
 * @date 2025/3/13 12:12
 */
public class LeetCode_75 {

    public void sortColors(int[] nums) {
        solution_1(nums);
    }

    //快排思想
    private void solution_1(int[] nums) {
        //1. 定义快慢指针
        int l=0,r= nums.length-1;
        for (int i = 0; i <= r; i++) {
            if(nums[i]>1){
                swap(nums,i,r);
                r--;
                i--;
            }else if(nums[i]<1){
                swap(nums,i,l);
                l++;
            }
        }


    }

    private void swap(int[] nums,int i,int j){
        int temp =nums[i];
        nums[i]=nums[j];
        nums[j]=temp;
    }


}
